# -*- coding;utf-8 -*-
"""
File name : MyCustomResponse.py.PY
Program IDE : PyCharm
Create file time: 2023/6/13 20:54
File Create By Author : 朱清闯
"""
from rest_framework.response import Response
from rest_framework.serializers import Serializer


class CustomResponse(Response):

    def __init__(self, data=None, code=None, msg=None, status=None, template_name=None, headers=None, exception=False,
                 content_type=None, **kwargs):
        super().__init__(None, status=status)
        if isinstance(data, Serializer):
            msg = "序列化错误"
            raise AssertionError(msg)
        self.data = {'code': code, 'msg': msg, 'data': data}
        self.data.update(kwargs)
        self.template_name = template_name
        self.exception = exception
        self.content_type = content_type
        if headers:
            for name, value in headers.items():
                self[name] = value
